import { GitRevisionPlugin } from 'git-revision-webpack-plugin'
import pxtorem from 'postcss-pxtorem'
import { defineConfig } from '@umijs/max'
import proxy from './proxy'
import routes from './routes'

const { REACT_APP_ENV, APP_ENV } = process.env

export default defineConfig({
  extraPostCSSPlugins: [
    pxtorem({
      rootValue: 100,
      unitPrecision: 5,
      propList: ['*'],
    }),
  ],
  headScripts: [
    {
      // src: './sh-data-engine/isOs.js',
      src: './isOs.js',
      // defer: true,
    },
    {
      content: `window.suanpan = window.location.pathname === '/' ? '' : window.location.pathname`,
      // charset: 'utf-8',
    },
    {
      // src: './sh-data-engine/flexible.js',
      src: './flexible.js',
      // defer: true,
    },
  ],
  metas: [
    { 'http-equiv': 'pragram', content: 'no-cache' },
    { 'http-equiv': 'expires', content: '0' },
    { 'http-equiv': 'cache-control', content: 'no-cache, no-store, must-revalidate' },
    { name: 'keywords', content: '数据集成引擎' },
    { name: 'description', content: '' },
  ],
  hash: true,
  layout: {
    locale: false,
  },
  initialState: {},
  model: {},
  // clientLoader: {},
  locale: {
    default: 'zh-CN',
    antd: true,
    baseNavigator: true,
  },
  targets: {
    chrome: 80,  // 默认值
  },
  routes,
  theme: {
    // 如果不想要 configProvide 动态设置主题需要把这个设置为 default
    // 只有设置为 variable， 才能使用 configProvide 动态设置主色调
    // https://ant.design/docs/react/customize-theme-variable-cn
    'root-entry-name': 'variable',
  },
  define: {
    'process.env': {
      APP_ENV: APP_ENV,
    },
  },
  ignoreMomentLocale: true,
  proxy: proxy[REACT_APP_ENV || 'dev'],
  manifest: {
    basePath: '/',
  },
  // publicPath: '/sh-data-engine/',
  publicPath: '/',
  fastRefresh: true,
  mfsu: {},
  history: {
    type: 'hash',
  },
  title: '-',
  antd: {},
  dva: {},
  favicons: ['./xuelanglog.png'],
  chainWebpack: (memo) => {
    memo.plugin('GitRevisionPlugin').use(GitRevisionPlugin)
  },
})
